package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.entity.ShoppingCart;
import com.itheima.service.impl.ShoppingCartServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartServiceImpl shoppingCartService;
    //加入购物车
    @PostMapping("/add")
    public R<ShoppingCart>add(@RequestBody ShoppingCart shoppingCart){
        return shoppingCartService.add (shoppingCart);
    }
    //查看购物车
    @GetMapping("/list")
    public R<List<ShoppingCart>> list(){
        return shoppingCartService.select ();
    }
    //清空购物车
    @DeleteMapping("/clean")
    public R<String>delete(){
        return shoppingCartService.delete ();
    }
    //减购物车
    @PostMapping("/sub")
    public R<ShoppingCart>sub(@RequestBody ShoppingCart shoppingCart){
        return shoppingCartService.sub (shoppingCart);
    }
}
